﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace FutureTech.Collection
{
        /// <summary>
        /// Enumerable Extensions
        /// </summary>
        public static class EnumerableExtensions
        {
                /// <summary>
                /// Automatics the observable collection.
                /// </summary>
                /// <typeparam name="T"></typeparam>
                /// <param name="lt">The lt.</param>
                /// <param name="ot">The ot.</param>
                /// <returns></returns>
                public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> lt, ObservableCollection<T> ot)
                {
                        ot.Clear();
                        foreach (var t in lt)
                        {
                                ot.Add(t);
                        }

                        return ot;
                }

                /// <summary>
                /// Automatics the observable collection.
                /// </summary>
                /// <typeparam name="T"></typeparam>
                /// <param name="lt">The lt.</param>
                /// <returns></returns>
                public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> lt)
                {
                        ObservableCollection<T> ts = new ObservableCollection<T>();

                        foreach (var t in lt)
                        {
                                ts.Add(t);
                        }

                        return ts;
                }

                /// <summary>
                /// Each of the collection item run action--function
                /// </summary>
                /// <typeparam name="T"></typeparam>
                /// <param name="lt">The lt.</param>
                /// <param name="action">The action.</param>
                public static void Each<T>(this IEnumerable<T> lt, Action<T> action)
                {
                        foreach (var t in lt)
                        {
                                action(t);
                        }
                }
        }
}